import Util from '../../utils/util.js';
import Status from '../../utils/status.js';

const app = getApp()
Component({
  properties: {
    current: {
      type: Number,
      value: 0,
      observer: function (newVal, oldNew) {
      }
    },
    amount: {
      type: Number,
      value: 0
    }
  },
  data: {
    tabbars: []
  },

  created() {
    const that = this;
  },

  attached: function () {
    const that = this
    Util.checkIphone().then(res => {//检查是否是iphone x/11等
      this.setData({isIphoneX: res})
      wx.createSelectorQuery().in(that).select('#tabbar')
        .boundingClientRect(function (rect) {
          let height = rect.height + 15
          that.triggerEvent('onLoadTabbar', height);
        }).exec()
    });

    let tabbar = Status.tabbarMenus()
    let is_deliver = wx.getStorageSync("is_deliver");
    if (is_deliver == 1) {
      tabbar[0].hidden = false;
    }
    this.setData({
      tabbars: tabbar
    })
  },

  ready() {
  },

  methods: {
    changeTabbar(e) {

      const that = this,
        index = e.currentTarget.dataset.key

      let tabbars = this.data.tabbars
      const current_path = app.getCurrentPathData();

      let is_deliver = wx.getStorageSync("is_deliver");
      if (is_deliver == 1) {
        tabbars[0].hidden = false;
        that.setData({
          tabbars: tabbars
        })
      }

      if (tabbars[index].noTab) {
        wx.redirectTo({
          url: tabbars[index].pagePath
        })
        return true;
      }

      wx.switchTab({
        url: tabbars[index].pagePath
      })
    },
  }
});
